<template>
    <div>
        <div style="margin: 10px 0; ">
            <el-input  placeholder="请输入学号" style="width: 400px;" suffix-icon="el-icon-search
    " v-model="studentId">
        </el-input ><el-button  class="ml-5" type="primary" @click="load" icon="el-icon-search">搜索</el-button>
        <el-button  class="ml-5" type="primary" @click="reset" icon="el-icon-refresh" >重置</el-button>
        <el-button  class="ml-5" type="primary" @click="run" icon="el-icon-check" >通过名单</el-button>
        </div>
        <div style="margin: 10px 0; ">
          <el-button type="primary">加分申请管理<i class="el-icon-user-solid"></i></el-button>
        </div>
    
        <el-table :data="tableData"  stripe :header-cell-class-name="headerBg" border @selection-change="handleSelectionChange">
          <el-table-column
          type="selection"
          width="55">
        </el-table-column>
          <el-table-column prop="studentId" label="学号" width="150">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="150">
            </el-table-column>
            <el-table-column prop="grade" label="年级" width="150">
            </el-table-column>
            <el-table-column prop="scho" label="申请奖项" width="150">
            </el-table-column>
            <el-table-column prop="scholarshipS" label="奖金" width="150">
            </el-table-column>
            <el-table-column prop="score" label="加权成绩" width="150">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="150">
            </el-table-column>
            <el-table-column prop="creatTime" label="申请时间" width="150">
            </el-table-column>
              <el-table-column>
                <template slot-scope="scope">
                  <el-button type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)"></el-button>
                  <el-popconfirm
                  confirm-button-text='确定'
                  cancel-button-text='取消'
                  icon="el-icon-info"
                  icon-color="red"
                  title="你确定删除该信息吗"
                  @confirm="del(scope.row)"
                  >
                  <el-button type="primary" icon="el-icon-delete" slot="reference"></el-button></el-popconfirm>
                </template>
              </el-table-column>
        </el-table>
        <div class="block" style="padding: 10px;">
        
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
       <!-- 弹窗 -->
      <el-dialog title="奖学金申请信息" :visible.sync="dialogFormVisible" >
      <el-form :model="form" label-width="100px">
        <el-form-item label="学号" >
          <el-input v-model="form.studentId" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="申请奖项" >
          <el-input v-model="form.scho" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="奖金" >
          <el-input v-model="form.scholarshipS" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="加权成绩" >
          <el-input v-model="form.score" autocomplete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请状态" >
          <el-input v-model="form.status" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="申请时间" >
          <el-input v-model="form.creatTime" autocomplete="off" disabled></el-input>
        </el-form-item>
      
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
    </div>
    </template>
    
    
    <script>
    
    import request from '../../utils/request';
    
    
    
    export default{
        name: 'Tuser',
        data(){
          
      return{
        tableData:[],
        total: 0,
        pageNum:1,
        pageSize: 5,
        studentId:'',
        status:'',
        headerBg:'headerBg',
        multipleSelection: [],
        dialogFormVisible: false,
        form:{
          studentId: '',
          name: '',
          age: '',
          contactInfo: '',
    
        }
      }
      },
      created(){
        this.load()
      },
      methods: {
      load(){
        request.get("/scholarship/all",{
          params:{
            pageNum : this.pageNum,
            pageSize: this.pageSize,
            studentId: this.studentId,
            status:this.status
            
          }
        }).then(res => {
          console.log(res)
          this.tableData = res.data.records
          this.total = res.data.total
        })
      },
      handleSizeChange(pageSize) {
        console.log(pageSize)
        this.pageSize = pageSize
        this.load()
       
      },
      handleCurrentChange(pageNum) {
        console.log(pageNum)
        this.pageNum = pageNum
       this.load()
      },
      // 重置按钮
      reset(){
        this.studentId=''
        this.load()
      },
      handleAdd(){
        this.dialogFormVisible = true
        this.form = {}
      },
      //新增
      save(){
        request.post('/scholarship/update',this.form).then(res =>{
          if(res.data.code == "0"){
            this.$message({
                message: res.data.msg,
                type: 'success'
               }),
            this.dialogFormVisible =  false
            this.load()
          }else{
            this.$message.error({
                
                message: res.data.msg,
                
               }),
            this.dialogFormVisible= false
          }
        })
      },
      //编辑
      handleEdit(row){
        this.form = row
        this.dialogFormVisible = true
      },
      //删除
      del(row){
        request.post("/scholarship/del",row).then(res =>{
          if(res.data.code == "0"){
            this.$message({
                message: res.data.msg,
                type: 'success'
               }),
            this.dialogFormVisible =  false
            this.load()
          }else{
            this.$message.error({
                
                message: res.data.msg,
                
               }),
            this.dialogFormVisible= false
          }
        })
      },
      run(){
        this.status = '审核通过'
        this.load()
      },
      
      handleSelectionChange(val){
        this.multipleSelection = val
      }
     }
    }
     
    </script>
    
    <style scoped>
    .headerBg{
      background-color: #bcb7b7!important;
    }
    </style>